# coding:utf-8
import time

__author__ = 'zhanghao.wen'

from lib.base import Base
from page.android import train_fare_details_page, train_register12306_account_page, train_login12306_page, train_debug_hu_page


class OTA12306ToLogin12306(Base):
    def __init__(self, method_name):
        Base.__init__(self, methodName=method_name)

        """
        本页元素
        """
        self.yuding_btn = train_fare_details_page.elements['预定']
        self.yuding_12306_btn = train_fare_details_page.elements['12306预订']
        self.shikebiao_btn = train_fare_details_page.elements['时刻表']

        """
        外部页面元素
        """
        self.login_12306_title = train_login12306_page.elements['登录12306账号title']
        self.register_12306_btn = train_login12306_page.elements['注册12306账号']
        self.noRegisterBuy_btn = train_login12306_page.elements['免注册购票通道']
        self.register_12306_title = train_register12306_account_page.elements['注册12306账号title']
        self.username_btn = train_register12306_account_page.elements['姓名']
        self.debug_hu_btn = train_fare_details_page.elements['debug胡']
        self.login12306_btn = train_debug_hu_page.elements['12306登录']
        self.isLogin12306_btn = train_debug_hu_page.elements['12306是否登录']

    def test_ota12306_to_login12306(self):
        """
        前提：未登陆12306(通过debug胡先退出登录)，OTA选择12306预订，跳转12306登录/注册
        1.跳转OTA页
        2.选择12306预订，跳转登录页
        3.点击注册12306
        4.断言跳转到12306页
        """
        self.open_schema_android('6013')
        time.sleep(8)
        self.click(self.debug_hu_btn)
        if self.text(self.isLogin12306_btn) == '已登录':
            self.click(self.login12306_btn)
        self.back()
        self.click(self.yuding_btn)
        self.click(self.yuding_12306_btn)
        time.sleep(3)
        self.check(self.login_12306_title)
        self.click(self.register_12306_btn)
        self.check(self.username_btn)